﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>周工艺能力预警</title>
    <link href="~/Scripts/jquery-easyui/themes/bootstrap/easyui.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-easyui/jquery.min.js"></script>
    <script src="~/Scripts/jquery-easyui/jquery.easyui.min.js"></script>
    <script src="~/Scripts/jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
    <link href="~/Content/themes/icon.css" rel="stylesheet" />
    <script src="~/Content/js/common.js"></script>
    <link href="~/Content/themes/table.css" rel="stylesheet" />
    </head>
    <body>
  <script>
      //周列显示样式处理函数
      function valuedisplay(value, row, index) {
          a = parseFloat(value).toFixed(1);
          p = value * 100 / (row.DayTime * 6) > 100 ? 100 : value * 100 / (row.DayTime * 6);
          if (value > row.AlertValue * row.DayTime * 6 / 100) {
              return '<div style="width:' + p + '%;height:20px;  line-height: 22px;  position:relative;background:red; "> <span style="text-align:right;  font-size: 14px; width:75px; position:absolute; ">' + a + '</span></div>';
          } else {
              return '<div style="width:' + p + '%;height:20px; line-height: 22px;   position:relative;background:green; "> <span style="text-align:right; font-size: 14px; width:75px; position:absolute; ">' + a + '</span></div>';
          }
      }
    //周产能预警
    //周产能预警--所有类型
    var week_all_adjust = 0;//定义距离本周前后n周的值；
    var week_all_removefinished = true;//周表移除已完成订单
    //预定义week列格式,周工序产能
    var week_all_Colums = [
            { field: 'OperGroupID', title: 'Code', width: 80, hidden: true },
              {
                  field: 'OperGroupName', title: '工艺', width: 50,
                  //formatter: function (value, row, index) { return largefont(value, row, index); }
              },
               { field: 'AlertValue', title: '预警%', width: 30 },
                {
                    field: 'DayTime', title: '周能力', width: 40,
                    formatter: function (value, row, index) { return value * 6; }
                },
                    {
                        field: '1', title: '1', width: 80,
                        formatter: function (value, row, index) {
                            return valuedisplay(value, row, index);
                        }
                    },
                 {
                     field: '2', title: '2', width: 80,
                     formatter: function (value, row, index) {
                         // return parseFloat(value).toFixed(1);
                         return valuedisplay(value, row, index);
                     }
                 },
                 {
                     field: '3', title: '3', width: 80,
                     formatter: function (value, row, index) {
                         return valuedisplay(value, row, index);
                     }
                 },
               {
                   field: '4', title: '4', width: 80,
                   formatter: function (value, row, index) {
                       return valuedisplay(value, row, index);
                   }
               },
               {
                   field: '5', title: '5', width: 80,
                   formatter: function (value, row, index) {
                       return valuedisplay(value, row, index);
                   }
               },
                 {
                     field: '6', title: '6', width: 80,
                     formatter: function (value, row, index) {

                         return valuedisplay(value, row, index);
                     }
                 }
    ];
    function week_all_datagrid(_week_all_adjust, refresh) {
        if (!refresh) { refresh = false; }
        $.ajax({     //请求当前数据的列名
            url: "/Home/GetCapacityAlert?r=" + Math.random(),
            type: "post",
            data: { adjustNum: _week_all_adjust, "key": "columns", "cycle": "week" },
            dataType: "json",
            timeout: 5000,
            success: function (data) {
                //动态更新Colums
                for (var i = 4; i < 10; i++) {
                    week_all_Colums[i].title = data.columns[i - 1].title;
                    week_all_Colums[i].field = data.columns[i - 1].field;
                };
                $("#weekCapacity_dg").datagrid({
                    url: "/Home/GetCapacityAlert?r=" + Math.random(),
                    queryParams: {
                        key: 'datarows',
                        cycle: "week",
                        adjustNum: _week_all_adjust,
                        removefinished: week_all_removefinished,
                        refresh: refresh,
                        classifyOper: true,
                        schedule: $('#schedule').val(),//排程方式
                        department: $('#Department').val()
                    },
                    striped: true, rownumbers: true, pagination: false, pageSize: 20, singleSelect: true,
                    fitColumns: true, fit: true,//自适应
                    pageList: [20, 40, 60, 80, 100],
                    //frozenColumns: [],
                    columns: [week_all_Colums],
                    //禁止行选中
                    onClickRow: function () {
                        $('#weekCapacity_dg').datagrid('clearSelections');
                    },
                    toolbar: [{
                        text: '上一周',
                        iconCls: 'icon-arrow_left',
                        handler: function () {
                            week_all_adjust--;
                            week_all_datagrid(week_all_adjust);
                        }
                    }, {
                        text: '下一周',
                        iconCls: 'icon-arrow_right',
                        handler: function () {
                            week_all_adjust++;
                            week_all_datagrid(week_all_adjust);
                        }
                    }, {
                        text: '本周',
                        iconCls: 'icon-arrow_undo',
                        handler: function () {
                            week_all_adjust = 0;
                            week_all_datagrid(week_all_adjust);
                        }
                    }, {
                        text: '刷新',
                        iconCls: 'icon-arrow_refresh',
                        handler: function () {
                            week_all_datagrid(week_all_adjust, true);
                        }

                    }, '-', { text: '过滤已完成订单:' }, {
                        id: 'sbweek_all'
                    }, '-',
                     //{
                     //    text: '导出',
                     //    iconCls: 'icon-page_excel',
                     //    handler: function () { exportDgData("week_all_time"); }
                     //},
                    ],
                    onLoadSuccess: function (data) {
                        $('#sbweek_all').switchbutton({
                            checked: week_all_removefinished,
                            onText: '是',
                            offText: '否',
                            onChange: function (checked) {
                                week_all_removefinished = checked;
                                week_all_datagrid(week_all_adjust);
                            }

                        });
                    }
                });

            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                if (textStatus == "timeout") {
                    $.show_alert("提示", "请求超时，请刷新当前页重试！");
                }
                else {
                    $.show_alert("错误", textStatus + "：" + errorThrown);
                }
            }
        })
    }
    $(function () {         
        week_all_datagrid(week_all_adjust,false);//周产能预警 
    })

    </script>

        <table id="weekCapacity_dg"></table>
            

    </body>
    </html>
